import baseService from '../baseService/index.js'
import {responseInterceptor} from './interceptor/index.js'

// 获取历史app版本列表
const getAppVersionListApi = async (fileOwnership)=>{
    try{
        let res = await baseService.post("/getHistoryAppPackageInfoList",{fileOwnership})
        return responseInterceptor(res)
    }catch(err){
        alert('未知异常')
    }

}

// 获取最新版的app信息
const getLatestAppInfoApi = async (fileOwnership)=>{
    try{
        let res = await baseService.post("/getAppInfo",{fileOwnership})
        return responseInterceptor(res)
    }catch(err){
        console.log('未知异常---',err)
        alert('未知异常')
    }
}


// 下载app
const  downloadAppApi = async (params)=>{
    try{
        let res = await baseService.post("/downloadFile",params)
        if(!res.ok){
            return responseInterceptor(res,'body')
        }
        return res
    }catch(err){
        alert('下载失败')
    }
}


// 上传app
const uploadAppPackageApi = async (formData)=>{
    console.log('上传的formData',formData,typeof formData);
    try{
        let res = await baseService.post("/uploadFile",formData,{type: 'formData'})
        return responseInterceptor(res)
    }catch(err){
        console.log('未知异常---',err)
        alert('未知异常')
    }
}

// 删除app信息
const deleteAppPackageApi = async (params)=>{
    try{
        let res = await baseService.post("/deleteFile",params)
        return responseInterceptor(res)
    }catch(err){
        console.log('未知异常---',err)
        alert('未知异常')
    }
}

export {
    getLatestAppInfoApi,
    downloadAppApi,
    getAppVersionListApi,
    uploadAppPackageApi,
    deleteAppPackageApi
}